<template>
	<div>
	  <input type="file" multiple @change="handleFileUpload" />
	  <button @click="submitFiles">上传文件</button>
	</div>
  </template>
  
  <script>
  export default {
	data() {
	  return {
		files: [],
	  };
	},
	methods: {
	  handleFileUpload(event) {
		this.files = event.target.files;
	  },
	  submitFiles() {
		if (this.files.length === 0) {
		  alert("请先选择文件");
		  return;
		}
  
		let formData = new FormData();
		for (let i = 0; i < this.files.length; i++) {
		  formData.append('files', this.files[i]);
		}

		console.log(this.files)
  
		fetch("http://127.0.0.1:8000/upload/", {
		  method: "POST",
		  body: formData,
		})
		  .then(response => response.json())
		  .then(data => {
			console.log(data);
		  })
		  .catch(error => {
			console.error("Error:", error);
		  });
	  },
	},
  };
  </script>
  